<template>
  <div class="vocab-app">
    <!-- 头部区域 -->
    <header class="app-header">
      <div class="container header-container">
        <div class="logo-container">
          <div class="placeholder-logo">
            <img src="/src/assets/images/4a3ece7aca9c3eee3c352f9b5ec3e6a8.jpg" alt="系统logo" class="logo-img">
          </div>
        </div>
        
        <div class="system-title">
          <h1>AI辅助学习系统-英语模块(词汇模块)</h1>
        </div>
        
        <div class="header-controls">
          <div class="function-buttons">
            <!-- 功能按钮 -->
            <button class="func-btn" title="词汇本管理">
              <span>📚</span>
            </button>
            <button class="func-btn" title="学习统计">
              <span>📊</span>
            </button>
            <button class="func-btn" title="高级搜索">
              <span>🔍</span>
            </button>

            <!-- 功能模块跳转按钮 -->
            <button class="func-btn" title="跳转到匹配练习页面" @click="goTo('/english/ma')">
              <span>🎯</span>
            </button>
            <button class="func-btn" title="跳转到自我测试页面" @click="goTo('/english/ust')">
              <span>📝</span>
            </button>
            <button class="func-btn" title="跳转到拼写练习页面" @click="goTo('/english/us')">
              <span>🔤</span>
            </button>
            
            <!-- 主题切换按钮 -->
            <button 
              class="theme-btn" 
              :class="isDarkMode ? 'dark' : 'light'"
              @click="toggleTheme"
              title="切换主题"
            >
              <span>{{ isDarkMode ? '🌞' : '🌙' }}</span>
            </button>
          </div>
        </div>
      </div>
    </header>

    <!-- 主内容区 -->
    <main class="main-content">
      <div class="container">
        <div class="function-bar">
          <!-- 书籍选择下拉框 -->
          <div class="book-selector">
            <select class="book-select" v-model="selectedBookId" @change="handleBookChange">
              <option value="">-- 选择词汇本 --</option>
              <option v-for="book in bookList" :key="book.bookId" :value="book.bookId">
                {{ book.bookName || `词汇本 ${book.bookId}` }}
              </option>
            </select>
          </div>
          
          <!-- 带切换功能的搜索框 -->
          <div class="search-with-toggle">
            <div class="search-toggle">
              <button 
                class="toggle-btn" 
                :class="{ active: searchMode === 'id' }"
                @click="searchMode = 'id'"
              >
                单词ID查询
              </button>
              <button 
                class="toggle-btn" 
                :class="{ active: searchMode === 'spell' }"
                @click="searchMode = 'spell'"
              >
                拼写查询
              </button>
            </div>
            <div class="search-input-group">
              <input 
                type="text" 
                v-model="advancedSearchKeyword" 
                :placeholder="searchMode === 'id' ? '请输入单词ID查询' : '请输入拼写查询'" 
                class="advanced-search-input"
                :inputmode="searchMode === 'id' ? 'numeric' : 'text'"
                @keyup.enter="handleAdvancedSearch"
              >
              <button class="search-btn" @click="handleAdvancedSearch">
                {{ searchMode === 'id' ? '查询ID' : '搜索拼写' }}
              </button>
            </div>
          </div>
          
          <!-- 词性筛选 -->
          <div class="filter-controls">
            <select class="filter-select" v-model="typeFilter" @change="handleFilterChange">
              <option value="all">全部类型</option>
              <option value="verb">动词</option>
              <option value="noun">名词</option>
              <option value="adjective">形容词</option>
              <option value="adverb">副词</option>
            </select>
          </div>
        </div>
        
        <div class="vocab-list-section">
          <h2 class="list-title">
            {{ currentBookName || '词汇学习列表' }}
            <span v-if="loading" class="loading-indicator">加载中...</span>
            <span v-if="errorMsg" class="error-message">⚠️ {{ errorMsg }}</span>
            <span v-if="searchResults.length > 0 && searchMode === 'spell'" class="search-result-count">
              找到 {{ searchResults.length }} 个匹配结果
            </span>
          </h2>
          
          <!-- 词汇卡片网格 -->
          <div class="vocab-grid">
            <!-- 单个词汇卡片 -->
            <div class="vocab-card" v-for="(item) in displayedVocabulary" :key="item.wordId">
              <div class="card-header">
                <h3 class="vocab-word" 
                    v-html="searchMode === 'spell' && advancedSearchKeyword 
                      ? highlightMatch(item.word, advancedSearchKeyword) 
                      : item.word">
                </h3>
                <span class="vocab-level" :class="getLevelClass(item.difficulty)">
                  {{ item.difficulty || 'Intermediate' }}
                </span>
              </div>
              
              <div class="vocab-info">
                <p class="pronunciation">
                  {{ item.pronunciation }} 
                  <button class="sound-btn" @click="playSound(item.word)" title="发音">🔊</button>
                </p>
                <p class="part-of-speech">{{ getPartOfSpeechText(item.partOfSpeech) }}</p>
                <!-- 新增：中文翻译显示区域 -->
                <p class="chinese-meaning" v-if="item.chinese">
                  {{ item.chinese }}
                </p>
              </div>
              
              <!-- 详情区域：仅当前点击卡片变化 -->
              <transition name="detail-expand">
                <div 
                  class="vocab-details" 
                  v-if="item.isExpanded"  
                ><!-- 使用v-if确保完全独立控制 -->
                  <p class="definition">{{ item.definition }}</p>
                  
                  <div class="example-container">
                    <p class="example-label">例句：</p>
                    <p class="example-content">{{ item.example || '暂无例句' }}</p>
                  </div>
                  
                  <p class="synonyms" v-if="item.synonyms && item.synonyms.length">
                    <strong>同义词：</strong>{{ item.synonyms.join('，') }}
                  </p>
                  <p class="ai-tip"><strong>AI提示：</strong>{{ item.aiTip || '点击展开更多学习提示...' }}</p>
                </div>
              </transition>
              
              <div class="card-actions">
                <button class="action-btn" @click="markAsKnown(item)" title="标记已掌握">✓</button>
                <button class="action-btn" @click="addToVocabList(item)" title="添加到生词本">+</button>
                <button 
                  class="action-btn toggle-detail-btn" 
                  @click="toggleDetails(item)"  
                  title="{{ item.isExpanded ? '收起详情' : '显示详情' }}"
                ><!-- 仅传递当前item -->
                  {{ item.isExpanded ? '−' : '+' }}
                </button>
              </div>
            </div>
            
            <!-- 空状态卡片 -->
            <div class="vocab-card empty-card" v-if="!loading && displayedVocabulary.length === 0 && !errorMsg">
              <div class="empty-placeholder">
                <p class="empty-text">当前词汇本暂无数据</p>
                <p class="empty-subtext">请选择其他词汇本或添加新单词</p>
              </div>
            </div>
          </div>
          
          <!-- 分页控制 -->
          <div class="pagination-controls">
            <button class="page-btn prev-btn" :disabled="currentPage === 1" @click="changePage(currentPage - 1)">
              上一页
            </button>
            <div class="page-info">
              第 {{ currentPage }} 页 / 共 {{ totalPages }} 页
            </div>
            <button class="page-btn next-btn" :disabled="currentPage >= totalPages" @click="changePage(currentPage + 1)">
              下一页
            </button>
          </div>
        </div>
      </div>
    </main>

    <!-- 底部区域 -->
    <footer class="app-footer">
      <div class="container footer-container">
        <div class="footer-info">
          <p class="copyright">© 2025 AI辅助学习系统 版权所有</p>
          <div class="footer-links">
            <router-link to="/system-info" class="footer-link">系统说明</router-link>
            <router-link to="/help" class="footer-link">使用帮助</router-link>
            <router-link to="/contact" class="footer-link">联系我们</router-link>
          </div>
        </div>
      </div>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import vocabularyService from '@/views/subjects/english/pages/vocabulary-study/script/vocabulary-js/vocabularyService.js';

// 路由实例
const router = useRouter();

// 页面跳转
const goTo = (path) => {
  router.push(path);
};

// 状态管理
const isDarkMode = ref(false);
const typeFilter = ref('all');
const currentPage = ref(1);
const totalPages = ref(1);
const loading = ref(false);
const errorMsg = ref('');
const currentBookName = ref('');
const allVocabulary = ref([]);
const sortedVocabulary = ref([]);

// 书籍选择相关
const bookList = ref([]);
const selectedBookId = ref('');

// 搜索相关
const searchMode = ref('id');
const advancedSearchKeyword = ref('');
const searchResults = ref([]);


// 筛选显示的词汇
const displayedVocabulary = computed(() => {
  const sourceData = searchResults.value.length > 0 ? searchResults.value : allVocabulary.value;
  
  // 应用词性筛选
  const filtered = sourceData.filter(item => {
    return typeFilter.value === 'all' || item.partOfSpeech.toLowerCase() === typeFilter.value;
  });
  
  // 计算总页数
  totalPages.value = Math.max(1, Math.ceil(filtered.length / 10));
  
  // 分页处理
  return filtered.slice((currentPage.value - 1) * 10, currentPage.value * 10);
});


// 页面初始化
onMounted(async () => {
  try {
    // 获取词汇本列表
    await fetchVocabBooks();
    
    // 默认选择第一个词汇本
    if (bookList.value.length > 0) {
      selectedBookId.value = bookList.value[0].bookId;
      await loadVocabularyByBookId(bookList.value[0].bookId);
    } else {
      errorMsg.value = '暂无可用的词汇本';
    }
  } catch (err) {
    errorMsg.value = '初始化失败：' + err.message;
  }

  // 初始化主题
  const savedTheme = localStorage.getItem('aiLearnTheme');
  if (savedTheme === 'dark') {
    isDarkMode.value = true;
    document.documentElement.classList.add('dark-theme');
  }
});


// 获取词汇本列表
const fetchVocabBooks = async () => {
  loading.value = true;
  try {
    bookList.value = await vocabularyService.getVocabBooks();
    return bookList.value;
  } catch (error) {
    errorMsg.value = error.message;
    throw error;
  } finally {
    loading.value = false;
  }
};


// 加载词汇
const loadVocabularyByBookId = async (bookId) => {
  if (!bookId || isNaN(bookId) || bookId <= 0) {
    errorMsg.value = '请选择有效的词汇本';
    return;
  }

  loading.value = true;
  errorMsg.value = '';
  searchResults.value = [];
  
  try {
    // 获取词汇数据并为每个单词添加独立的展开状态
    const words = await vocabularyService.getWordsByBookId(bookId);
    allVocabulary.value = words.map(word => ({
      ...word,
      isExpanded: false  // 每个单词独立的展开状态
    }));
    
    // 排序
    sortedVocabulary.value = [...allVocabulary.value].sort((a, b) => a.wordId - b.wordId);
    
    // 更新当前词汇本名称
    const currentBook = bookList.value.find(b => b.bookId === Number(bookId));
    currentBookName.value = currentBook ? currentBook.bookName : `词汇本 ${bookId}`;
    currentPage.value = 1;
  } catch (err) {
    errorMsg.value = err.message;
    allVocabulary.value = [];
    sortedVocabulary.value = [];
  } finally {
    loading.value = false;
  }
};


// 处理书籍选择变化
const handleBookChange = async () => {
  const bookId = Number(selectedBookId.value);
  if (bookId) {
    await loadVocabularyByBookId(bookId);
  } else {
    allVocabulary.value = [];
    sortedVocabulary.value = [];
    currentBookName.value = '';
  }
};


// 高级搜索
const handleAdvancedSearch = async () => {
  const keyword = advancedSearchKeyword.value.trim();
  errorMsg.value = '';
  
  if (!keyword) {
    searchResults.value = [];
    return;
  }
  
  try {
    if (searchMode.value === 'id') {
      // ID查询
      if (!/^\d+$/.test(keyword)) {
        throw new Error('ID查询请输入数字');
      }
      
      const targetIndex = Number(keyword) - 1;
      
      if (!selectedBookId.value) {
        throw new Error('请先选择词汇本');
      }
      
      if (targetIndex < 0 || targetIndex >= sortedVocabulary.value.length) {
        throw new Error(`未找到ID为 ${keyword} 的单词（范围：1-${sortedVocabulary.value.length}）`);
      }
      
      searchResults.value = [sortedVocabulary.value[targetIndex]];
    } else {
      // 拼写查询
      if (!selectedBookId.value) {
        throw new Error('请先选择词汇本');
      }
      
      if (allVocabulary.value.length === 0) {
        throw new Error('当前词汇本没有可搜索的单词');
      }
      
      const spell = keyword.toLowerCase();
      searchResults.value = allVocabulary.value.filter(word => {
        const wordMatch = word.word.toLowerCase().includes(spell);
        const definitionMatch = word.definition.toLowerCase().includes(spell);
        const exampleMatch = word.example.toLowerCase().includes(spell);
        // 新增：支持中文翻译搜索
        const chineseMatch = word.chinese && word.chinese.toLowerCase().includes(spell);
        return wordMatch || definitionMatch || exampleMatch || chineseMatch;
      });
      
      if (searchResults.value.length === 0) {
        throw new Error(`未找到包含 "${keyword}" 的单词`);
      }
    }
    currentPage.value = 1;
  } catch (err) {
    errorMsg.value = err.message;
    searchResults.value = [];
  }
};


// 高亮匹配文本
const highlightMatch = (text, keyword) => {
  if (!keyword) return text;
  
  const regex = new RegExp(`(${keyword})`, 'gi');
  return text.replace(regex, '<span class="highlight-match">$1</span>');
};


// 主题切换
const toggleTheme = () => {
  isDarkMode.value = !isDarkMode.value;
  if (isDarkMode.value) {
    document.documentElement.classList.add('dark-theme');
    localStorage.setItem('aiLearnTheme', 'dark');
  } else {
    document.documentElement.classList.remove('dark-theme');
    localStorage.setItem('aiLearnTheme', 'light');
  }
};


// 分页控制
const changePage = (pageNum) => {
  if (pageNum >= 1 && pageNum <= totalPages.value) {
    currentPage.value = pageNum;
  }
};


// 其他辅助方法
const handleFilterChange = () => {
  currentPage.value = 1;
};

const playSound = (word) => {
  const synth = window.speechSynthesis;
  const utterance = new SpeechSynthesisUtterance(word);
  utterance.lang = 'en-US';
  synth.speak(utterance);
};

const markAsKnown = (item) => {
  console.log(`标记${item.word}为已掌握`);
  const tempText = item.word;
  item.word = '✓ ' + item.word;
  setTimeout(() => {
    item.word = tempText;
  }, 1500);
};

const addToVocabList = (item) => {
  console.log(`将${item.word}添加到生词本`);
  const tempText = item.word;
  item.word = '+ ' + item.word;
  setTimeout(() => {
    item.word = tempText;
  }, 1500);
};

/**
 * 核心功能：仅切换当前点击卡片的状态，完全独立
 * 不操作任何其他卡片的属性
 */
const toggleDetails = (item) => {
  // 只修改当前点击项的展开状态，与其他卡片完全隔离
  item.isExpanded = !item.isExpanded;
  
  // AI提示逻辑
  if (item.isExpanded && !item.aiTip) {
    item.aiTip = `尝试记住"${item.word}"作为${getPartOfSpeechText(item.partOfSpeech)}的用法`;
  }
};

const getPartOfSpeechText = (pos) => {
  const posMap = {
    'noun': '名词 (noun)',
    'verb': '动词 (verb)',
    'adjective': '形容词 (adjective)',
    'adverb': '副词 (adverb)',
    'pronoun': '代词 (pronoun)',
    'prep': '介词 (prep)',
    'conj': '连词 (conj)',
    'interj': '感叹词 (interj)'
  };
  return posMap[pos] || pos;
};

const getLevelClass = (level) => {
  const levelMap = {
    'Beginner': 'level-beginner',
    'Intermediate': 'level-intermediate',
    'Advanced': 'level-advanced'
  };
  return levelMap[level] || 'level-intermediate';
};
</script>

<style scoped>
/* 高亮样式 */
.highlight-match {
  background-color: rgba(245, 158, 11, 0.3);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: bold;
}

/* 新增：中文翻译样式 */
.chinese-meaning {
  font-size: 14px;
  color: var(--text-primary);
  margin: 8px 0 10px 0;
  padding: 2px 6px;
  background-color: rgba(79, 70, 229, 0.05);
  border-radius: 4px;
}

/* 核心样式：确保卡片独立性 */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;  /* 足够的间距避免相互影响 */
  margin-bottom: 32px;
}

.vocab-card {
  background-color: var(--bg-primary);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  padding: 20px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
  /* 关键：使用min-height而非固定height，内容多时自然扩展但不影响其他卡片 */
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

/* 详情区域样式 */
.vocab-details {
  margin: 16px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 动画效果：只影响当前卡片 */
.detail-expand-enter-active,
.detail-expand-leave-active {
  transition: all 0.3s ease;
  max-height: 500px;
}

.detail-expand-enter-from,
.detail-expand-leave-to {
  opacity: 0;
  transform: translateY(-10px);
  max-height: 0;
  overflow: hidden;
}

/* 其他样式保持不变 */
.search-result-count {
  margin-left: 10px;
  font-size: 0.9rem;
  color: var(--primary-color);
  font-weight: normal;
}

:root {
  --primary-color: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #4338ca;
  --secondary-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border-color: #e5e7eb;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --transition-speed: 0.3s;
}

.dark-theme {
  --text-primary: #f3f4f6;
  --text-secondary: #d1d5db;
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --border-color: #374151;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.5;
}

.vocab-app {
  min-height: 100vh;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  transition: background-color var(--transition-speed);
}

.logo-img {
  width: 50px;
  height: 50px;
  border-radius: 30px;
  object-fit: cover;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-header {
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  padding: 12px 0;
  transition: all var(--transition-speed);
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.logo-container {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.system-title {
  flex: 1;
  margin: 0 20px;
  min-width: 200px;
}

.system-title h1 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.function-buttons {
  display: flex;
  gap: 8px;
}

.func-btn, .theme-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.func-btn:hover, .theme-btn:hover {
  transform: scale(1.1);
  background-color: var(--primary-color);
  color: white;
}

.main-content {
  padding: 24px 0;
}

.function-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  align-items: center;
  justify-content: flex-start;
}

.book-selector {
  min-width: 180px;
}

.book-select, .filter-select {
  width: 100%;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.book-select:focus, .filter-select:focus {
  outline: none;
  border-color: var(--primary-color);
}

.search-with-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 300px;
}

.search-toggle {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.toggle-btn {
  padding: 10px 16px;
  background-color: var(--bg-secondary);
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:first-child {
  border-right: 1px solid var(--border-color);
}

.toggle-btn.active {
  background-color: var(--primary-color);
  color: white;
}

.search-input-group {
  display: flex;
  flex: 1;
  min-width: 200px;
}

.advanced-search-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.advanced-search-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.search-btn {
  padding: 10px 16px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.search-btn:hover {
  background-color: var(--primary-dark);
}

.filter-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.vocab-list-section {
  margin-top: 20px;
}

.list-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.vocab-word {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary-color);
  margin: 0;
  transition: color 0.2s;
}

.vocab-card:hover .vocab-word {
  color: var(--primary-dark);
}

.vocab-level {
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.level-beginner {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--secondary-color);
}

.level-intermediate {
  background-color: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.level-advanced {
  background-color: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
}

.vocab-info {
  margin-bottom: 16px;
}

.pronunciation {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sound-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sound-btn:hover {
  background-color: var(--primary-color);
  color: white;
}

.part-of-speech {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 10px 0;
  padding: 2px 6px;
  background-color: var(--bg-secondary);
  border-radius: 4px;
  display: inline-block;
}

.example-container {
  background-color: rgba(79, 70, 229, 0.05);
  border-left: 3px solid var(--primary-color);
  padding: 12px 16px;
  border-radius: 4px;
  margin: 8px 0;
}

.example-label {
  font-weight: 600;
  color: var(--primary-color);
  margin: 0 0 6px 0;
  font-size: 14px;
}

.example-content {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  font-style: italic;
}

.synonyms {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.ai-tip {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--warning-color);
  font-style: italic;
  margin-top: 8px;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: auto; /* 推到卡片底部 */
}

.action-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-btn:hover {
  background-color: var(--primary-color);
  color: white;
}

.toggle-detail-btn {
  background-color: rgba(79, 70, 229, 0.1);
  color: var(--primary-color);
}

.empty-card {
  background-color: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.empty-placeholder {
  text-align: center;
  padding: 20px;
}

.empty-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0 0 8px 0;
}

.empty-subtext {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.page-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn:hover:not(:disabled) {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--bg-secondary);
}

.page-info {
  font-size: 14px;
  color: var(--text-secondary);
}

.app-footer {
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  padding: 24px 0;
  margin-top: 40px;
}

.footer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.footer-info {
  text-align: center;
}

.copyright {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 12px 0;
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-link {
  font-size: 14px;
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

.loading-indicator {
  margin-left: 10px;
  font-size: 0.9rem;
  color: var(--primary-color);
}

.error-message {
  margin-left: 10px;
  font-size: 0.9rem;
  color: var(--danger-color);
  display: flex;
  align-items: center;
  gap: 4px;
}

@media (max-width: 1024px) {
  .function-bar {
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 12px 16px;
  }
  
  .system-title {
    margin: 0;
    width: 100%;
  }
  
  .system-title h1 {
    font-size: 1.1rem;
    text-align: left;
  }
  
  .header-controls {
    width: 100%;
    justify-content: flex-end;
  }
  
  .function-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-with-toggle {
    min-width: auto;
    width: 100%;
  }
  
  .filter-controls {
    width: 100%;
    justify-content: flex-start;
  }
  
  .vocab-grid {
    grid-template-columns: 1fr;
  }
}

.dark-theme .vocab-app {
  --bg-secondary: #1f2937;
  --bg-primary: #374151;
  --text-primary: #f3f4f6;
  --text-secondary: #d1d5db;
  --border-color: #4b5563;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.dark-theme .highlight-match {
  background-color: rgba(245, 158, 11, 0.5);
}

.dark-theme .example-container {
  background-color: rgba(79, 70, 229, 0.15);
}

.dark-theme .chinese-meaning {
  background-color: rgba(79, 70, 229, 0.15);
}

.dark-theme .sound-btn:hover,
.dark-theme .action-btn:hover,
.dark-theme .theme-btn:hover,
.dark-theme .func-btn:hover {
  background-color: var(--primary-light);
}

.dark-theme .search-btn:hover {
  background-color: var(--primary-light);
}

.dark-theme .filter-select,
.dark-theme .book-select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d1d5db' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

.dark-theme .toggle-btn {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
}

.dark-theme .toggle-btn.active {
  background-color: var(--primary-color);
  color: white;
}
</style>
